#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-11-17 9:24 上午
# @Author  : yangdy
# @File    : 2020-11-17.1030.距离顺序排列矩阵单元格
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def allCellsDistOrder(self, R: int, C: int, r0: int, c0: int) -> List[List[int]]:
        ans = [[r, c] for r in range(R) for c in range(C)]
        ans.sort(key=lambda x: abs(x[0]-r0)+abs(x[1]-c0))
        return ans
